package com.hiltony.web.serviceImpl;

import com.hiltony.web.mapper.StatisticsMapper;
import com.hiltony.web.model.dto.*;
import com.hiltony.web.service.StatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by hzyangxin1 on 2016/11/12.
 *
 */
@Service
public class StatisticsServiceImp implements StatisticsService {

    @Resource
    private StatisticsMapper statisticsMapper;

    @Override
    public List<GenderStatDto> statGender() {
         List<GenderStatDto> genderStat = statisticsMapper.statGender();
        if (genderStat==null){
            return new ArrayList<>();
        }
        else {
            return genderStat;
        }
    }

    @Override
    public List<AgeStatDto> statAge() {
        List<AgeStatDto> ageStat = statisticsMapper.statAgePeriod();
        if (ageStat==null){
            return new ArrayList<>();
        }
        else {
            return ageStat;
        }
    }

    @Override
    public DiseaseDayCntStatDto getDiseaseStatCnt(StatCondition condition){
        return statisticsMapper.getDiseaseStatCnt(condition);
    }

    @Override
    public List<WarningStatDto> getWarningStat(StatCondition condition){
        List<WarningStatDto> warningStatDtoList = statisticsMapper.getWarningStat(condition);
        for (WarningStatDto dto:warningStatDtoList){
            dto.setTotalCnt(statisticsMapper.statMemberCntOnLogday(dto.getLogday()));
        }
        return warningStatDtoList;
    }
}
